// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name:   Parent.java

package org.covalence;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import org.covalence.core.Observable;
import org.covalence.core.util.CPropertyChangeSupport;
import org.covalence.core.util.CTable;

// Referenced classes of package org.covalence:
//            Child

public class ParentEnh
    implements Observable
{

    public ParentEnh()
    {
        name = "Daddy";
        child = new Child();
        _pcs = new CPropertyChangeSupport(this);
        ((Observable)this).addNestedObservable((Observable)child, "child");
        ((Observable)child).setParent((Observable)this);
    }

    public Child getChild()
    {
        return child;
    }

    public void setChild(Child child)
    {
    	this._pcs.moveListeners(((Observable) this.child), (Observable) child);
    	
        if((child instanceof Observable) && ((Observable)child).getParent() != this)
        {
            addNestedObservable((Observable)child, "child");
            ((Observable)child).setParent(this);
            this._pcs.moveListeners(((Observable) this.child), (Observable) child);
        }
        Child child1 = this.child;
        Child child2 = child;
        this.child = child;
        _pcs.firePropertyChange("child", child1, child2);
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        String s = this.name;
        String s1 = name;
        this.name = name;
        _pcs.firePropertyChange("name", s, s1);
    }

    public void addPropertyChangeListener(PropertyChangeListener propertychangelistener)
    {
        _pcs.addPropertyChangeListener(propertychangelistener);
    }

    public void removePropertyChangeListener(PropertyChangeListener propertychangelistener)
    {
        _pcs.removePropertyChangeListener(propertychangelistener);
    }

    public void addNestedObservable(Observable observable, String s)
    {
        observable.setNestedPropertyName(s);
        if(!CTable.isCollectionType(observable.getClass().getName()))
            addPropertyChangeListener(observable);
    }

    public void setNestedPropertyName(String s)
    {
        _nestedPropertyName = s;
    }

    public Object getParent()
    {
        return _parent;
    }

    public void setParent(Observable observable)
    {
        _parent = observable;
    }

    public void propertyChange(PropertyChangeEvent propertychangeevent)
    {
        if(propertychangeevent.getSource() == _parent && propertychangeevent.getPropertyName().equals(_nestedPropertyName))
            fireAll();
        else
            _pcs.firePropertyChange(propertychangeevent);
    }

    public PropertyChangeListener[] getPropertyChangeListeners() {
		return _pcs.getPropertyChangeListeners();
	}

	private void fireAll()
    {
        _pcs.firePropertyChange("child", null, child);
        _pcs.firePropertyChange("name", null, name);
    }

    private CPropertyChangeSupport _pcs;
    private Observable _parent;
    private String _nestedPropertyName;
    private String name;
    private Child child;
}
